package com.jz.netthings.bloodsources.bean;

import com.baomidou.mybatisplus.enums.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.jz.netthings.bloodsources.utils.BloodSourcesDateUtils;
import lombok.Data;

import java.io.Serializable;

/**
 * <p>
 * 献浆提醒记录
 * </p>
 *
 * @author 张凡
 * @since 2019-08-03
 */
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class XyRemind implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    /**
     * 浆员卡号
     */
    @TableField("cardId")
    private String cardId;
    /**
     * 提醒的浆员ID
     */
    @TableField("remindProviderId")
    private Long remindProviderId;
    /**
     * 提醒浆员姓名
     */
    @TableField("remindProviderName")
    private String remindProviderName;
    /**
     * 提醒日期
     */
    @TableField("remindDate")
    @JsonFormat(pattern="yyyy-MM-dd")
    private Date remindDate;
    /**
     * 下次采浆日期
     */
    @TableField("nextCollDate")
    @JsonFormat(pattern="yyyy-MM-dd")
    private Date nextCollDate;
    /**
     * 完成提醒时间
     */
    @TableField("overRemindTime")
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date overRemindTime;
    /**
     * 完成提醒用时
     */
    @TableField("overConsumTime")
    private String overConsumTime;
    /**
     * 提醒项目（; 隔开）
     */
    @TableField("remindProject")
    private String remindProject;
    /**
     * 浆站提醒项
     */
    @TableField("jzInfoDataItem")
    private String jzInfoDataItem;
    /**
     * 浆员反馈项
     */
    @TableField("jzInfoDataResponse")
    private String jzInfoDataResponse;
    /**
     * 提醒反馈
     */
    @TableField("remindFeeback")
    private String remindFeeback;
    /**
     * 预计献浆日期
     */
    @TableField("estimateCollDate")
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date estimateCollDate;
    /**
     * 最近1次献浆日期
     */
    @TableField("collectionDate")
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date collectionDate;
    /**
     * 提醒状态
     */
    @TableField("remindStatus")
    private Integer remindStatus;

    /**
     * 提醒护士ID
     */
    @TableField("remindNurseId")
    private Long remindNurseId;
    /**
     * 提醒护士姓名
     */
    @TableField("remindNurseName")
    private String remindNurseName;
    /**
     * 提醒护士部门ID
     */
    @TableField("remindNurseDeptId")
    private String remindNurseDeptId;
    /**
     * 提醒方式
     */
    @TableField("remindWay")
    private Integer remindWay;
    /**
     * 回访记录
     */
    @TableField("returnVisitRecored")
    private String returnVisitRecored;
    /**
     * 提醒回访内容 1.延期献浆| 2.浆员无意愿后续献浆
     */
    @TableField("remindSubmit")
    private String remindSubmit;

    /**
     * 提醒回访内容 1.延期献浆| 2.浆员无意愿后续献浆
     */
    @TableField(exist = false)
    private Boolean isAgingPulping = false;


    public Long getId() {
        return id;
    }

    public String getCardId() {
        return cardId;
    }

    public void setCardId(String cardId) {
        this.cardId = cardId;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getRemindProviderId() {

        return (remindProviderId==null||"".equals(remindProviderId+"")?0:remindProviderId);
    }

    public void setRemindProviderId(Long remindProviderId) {
        this.remindProviderId = remindProviderId;
    }
    public String getRemindProviderName() {
        return remindProviderName;
    }
    public void setRemindProviderName(String remindProviderName) {
        this.remindProviderName = remindProviderName;
    }
    public Date getRemindDate() {
        return remindDate;
    }

    public void setRemindDate(Date remindDate) {
        this.remindDate = remindDate;
    }

    public Date getNextCollDate() {
        return nextCollDate;
    }

    public void setNextCollDate(Date nextCollDate) {
        this.nextCollDate = nextCollDate;
    }

    public Date getOverRemindTime() {
        return overRemindTime;
    }

    public void setOverRemindTime(Date overRemindTime) {
        this.overRemindTime = overRemindTime;
    }

    public String getOverConsumTime() {
        return overConsumTime;
    }

    public void setOverConsumTime(String overConsumTime) {
        this.overConsumTime = overConsumTime;
    }

    public String getRemindProject() {
        return remindProject;
    }

    public void setRemindProject(String remindProject) {
        this.remindProject = remindProject;
    }

    public String getRemindFeeback() {
        return remindFeeback;
    }

    public void setRemindFeeback(String remindFeeback) {
        this.remindFeeback = remindFeeback;
    }

    public Date getEstimateCollDate() {
        return estimateCollDate;
    }

    public void setEstimateCollDate(Date estimateCollDate) {
        this.estimateCollDate = estimateCollDate;
    }

    public Date getCollectionDate() {
        return collectionDate;
    }

    public void setCollectionDate(Date collectionDate) {
        this.collectionDate = collectionDate;
    }

    public String getJzInfoDataItem() {
        return jzInfoDataItem;
    }

    public void setJzInfoDataItem(String jzInfoDataItem) {
        this.jzInfoDataItem = jzInfoDataItem;
    }

    public String getJzInfoDataResponse() {
        return jzInfoDataResponse;
    }

    public void setJzInfoDataResponse(String jzInfoDataResponse) {
        this.jzInfoDataResponse = jzInfoDataResponse;
    }

    public Integer getRemindStatus() {
        return remindStatus;
    }

    public void setRemindStatus(Integer remindStatus) {
        this.remindStatus = remindStatus;
    }

    public Long getRemindNurseId() {
        return (remindNurseId==null||"".equals(remindNurseId+"")?0:remindNurseId);
    }

    public void setRemindNurseId(Long remindNurseId) {
        this.remindNurseId = remindNurseId;
    }

    public String getRemindNurseDeptId() {
        return remindNurseDeptId;
    }

    public void setRemindNurseDeptId(String remindNurseDeptId) {
        this.remindNurseDeptId = remindNurseDeptId;
    }

    public String getRemindNurseName() {
        return remindNurseName;
    }

    public void setRemindNurseName(String remindNurseName) {
        this.remindNurseName = remindNurseName;
    }

    public Integer getRemindWay() {
        return remindWay;
    }

    public void setRemindWay(Integer remindWay) {
        this.remindWay = remindWay;
    }

    public String getReturnVisitRecored() {
        return returnVisitRecored;
    }

    public void setReturnVisitRecored(String returnVisitRecored) {
        this.returnVisitRecored = returnVisitRecored;
    }

    public String getRemindSubmit() {
        return remindSubmit;
    }

    public void setRemindSubmit(String remindSubmit) {
        this.remindSubmit = remindSubmit;
    }

    public Boolean getAgingPulping() {
        return isAgingPulping;
    }

    public void setAgingPulping(Boolean agingPulping) {
        isAgingPulping = agingPulping;
    }

    /**
     * 判断是否需要生成未献浆记录
     * @return
     * @throws Exception
     */
    @JsonIgnoreProperties({ "internalId", "secretKey" })
    public Boolean isNoPulping() throws  Exception{
        Boolean isNoPulping = false;
        //获取当前时间
         Date curDate = BloodSourcesDateUtils.getCurrentDate();
        //获取预计献浆时间
        Date estimateCollPupingDate = this.getEstimateCollDate();
        //获取最近一次采浆记录 如果
        Date collPulpingDate =  this.getCollectionDate();
        if(collPulpingDate==null ||"".equals( collPulpingDate) ){
            return  isNoPulping;
        }
        //求当前时间与预计献浆时间的差值 单位/天
        Long dDays = BloodSourcesDateUtils.DdateForTwoDate(curDate ,estimateCollPupingDate);
        //如果已经过了预计献浆时间1天了 就开始判定该提醒的浆员最近1次献浆记录时间是否与预计的献浆记录时间相差不大
        if(dDays==1L){
            //判定
                if(isPulping(estimateCollPupingDate,collPulpingDate)){
                    isNoPulping = true;
                }else{
                    isNoPulping = false;
                }
        }else
         if(dDays>1L){  //如果是以后的话,则每天定时任务进行该预计献浆时间-近期献浆时间，如果后面该浆员有献浆记录了（即近期献浆时间-预计献浆时间>0）,则可以激活未献浆记录里面的已再次献浆的参数
                        //通过浆员Id进行数据更新
             isNoPulping = isPulping(estimateCollPupingDate,collPulpingDate);
         }
        return isNoPulping;
    }

    /**
     * 判断2个时间差值是否在规定的时间内 单位【天】
     * @param maxDate  被减值
     * @param minDate  减值
     * @return
     */
    public Boolean isPulping(Date maxDate,Date minDate){
        Boolean isPulping = false;
        //获取到两个时间相差的天数
        Long splitVal = ((maxDate.getTime()-minDate.getTime())/1000/60/60/24);
        //判定当前Long 值是否大于0
        if(splitVal>=0){ //如果预计献浆的时间大于最近一次献浆的时间 预计-最近献浆>=0;
                         //判定其是否是14天以前的数据
            if(splitVal<=14){   //如果是14天内的数据，则表明该浆员在预计时间之内按时来献浆了，则不生成未献浆记录
                isPulping = false;
            }else{
                if(splitVal==15L){//如果差值大于献浆最低间隔时间15天，则表示该浆员这轮预计献浆没有来，则生成未献浆记录
                    isPulping = true;
                }else if((splitVal%15)==0L){
                    isPulping = true;
                }
            }
        }else{           //如果 预计-最近献浆<0 表示 该浆员过了预计献浆时间过后又进行了献浆，则表示其后续进行了献浆，则表示该浆员后续再次献浆了
                 this.setIsAgingPulping(true);
        }
        return isPulping;
    }

    public static void main(String[] args) {
        long max = 5000;
        long min = 5500;
        System.out.println((999*3600*24)/1000/3600/24);
    }
}
